/**
 * @created by wy on 2019-7-9 10:13:24
 * @updated by
 * @description dashboard
 */
define([
	'./themes/lang/' + window.YUFP_SYS_CONFIG.language + '/pages/common/dashboard/dashboard.js',
	'libs/echarts/echarts-3.8.5.min.js'
], function(require, exports) {
	/**
	 * 页面加载完成时触发
	 * @param hashCode 路由ID
	 * @param data 传递数据对象
	 * @param cite 页面站点信息
	 */
	exports.ready = function(hashCode, data, cite) {
		yufp.lookup.reg('CUST_LEVEL,ANNOUNCEMENT_STATUS');
		var vm = yufp.custom.vue({
			el: cite.el,
			data: function() {
				return {
					// 客户概览url
					gridCustomerDataUrl:backend.msmFrontWebService + '/api/dashBoard/getEachGridData',
					gridCustomerDialogVisible:false,
					gridCustomerData:{condition: JSON.stringify({
							userId: yufp.session.userId,
							orgId: yufp.session.user.org.code,
							roleId:yufp.session.user.roles[0].code,
						})},
					//客户资产分布
					customerAssetsDataUrl:backend.msmFrontWebService + '/api/dashBoard/getCustAssetDistrDetail',
					customerAssetsDialogVisible:false,
					customerAssetsData:{condition: JSON.stringify({
							userId: yufp.session.userId,
							orgId: yufp.session.user.org.code,
							roleId:yufp.session.user.roles[0].code,
						})},
					//公告
					announcementManagementDialogVisible:false,
					announcementManagementDataUrl:backend.msmFrontWebService + '/api/dashBoard/getPublishedNotice',
					announcementManagementData:{condition: JSON.stringify({
							userId: yufp.session.userId,
							orgId: yufp.session.user.org.code,
							roleId:yufp.session.user.roles[0].code,
						})},
					customerBirthdayData:[],
					activeName: 'first',
					themeColor: yufp.frame.baseFrame.themes.color,
					userId: yufp.session.userId,
					echartOptionzc: {},
					mainData: {
						gridNum:0,
						custNum:0,
						importCustNum:0,
						documentCustNumD:0,
					},
					productExpirationUndo:0,
					repaymentReminderUndo:0,
					customerBirthdayUndo:0,
					overdueReminderUndo:0,
					largeMovingAccountUndo:0,
					importantCustUndo:0,
					wealthReminderUndo:0,
					withdrawalInAdvanceUndo:0,
					conversionRateData:[],
					transformationNumberData:[],
					noticeData: [],
					isSelected: true,
					isSelected1: false,
					productExpirationData:[],
					overdueReminderData:[],
					repaymentReminderData:[],
					largeMovingAccountData:[],
					withdrawalInAdvanceData:[],
					wealthReminderData:[],
					importantCustData:[],
					rankData:[],
					echartOptiongl :{},
					isImport:'',
					custNo:'',
					remindInfo:{
						custName:"",
						custNo:"",
						telNo:"",
						custLevel:"",
						remindDetail:"",
					},
					remindFormVisible:false
				};
			},
			created: function () {
				this.getPublishedBoard()
				this.getCustomerBirthday()
				this.getCustAssetDistr()
				this.getGridMainData()
				this.getEachGridData()
				this.getProductExpiration()
				this.getTransformationNumberList()
				this.getConversionRateList()
				this.getOverdueReminder()
				this.getLargeMovingAccount()
				this.getImportantCust()
				this.getWealthReminder()
				this.getWithdrawalInAdvance()
				this.getRepaymentReminder()
				this.getTaskOverview()
			},
			filters: {
				numFilter (value) {
					// 截取当前数据到小数点后两位
					value = Number(value)
					let realVal = (value/10000).toFixed(2)
					return realVal
				},
				numFilters (value) {
					// 截取当前数据到小数点后四位
					value = Number(value)
					let realVal = parseFloat(value).toFixed(4)
					return realVal
				}
			},
			methods: {
				dateFormat: function(row, column) {
					if (row.createTime){
						let dt = new Date(row.createTime)
						return dt.getFullYear()+'-'+(dt.getMonth()+1)+'-'+ dt.getDate()
					}
					else {
						return null
					}
				},
				showDialog:function (type){
					var me =this;
					if (type === 'gridCustomer'){
						me.gridCustomerDialogVisible = true;
					}if (type === 'custAssetDistr'){
						me.customerAssetsDialogVisible = true;
					}if (type === 'remindForm'){
						me.remindFormVisible = true;
					}if (type === 'announcementManagement'){
						me.announcementManagementDialogVisible = true;
					}
				},
				updateImport:function (isImport,custNo){
					var me =this;
					yufp.service.request({
						url: backend.msmFrontWebService + '/api/CustCenter/updateCustomerImport',
						method: 'get',
						data: {
							condition: JSON.stringify({
								isImport:isImport,
								crtOprtrNo:yufp.session.userId,
								custNo:custNo
							})
						},
						callback: function (code, message, response) {
							if (code === 0) {
								if (isImport === "0"){
									me.isImport="1"
									me.$message({message: '添加重点客户成功', type: 'success'});
								}
								if(isImport === "1"){
									me.isImport="0"
									me.$message({message: '取消重点客户成功', type: 'success'});
								}
								//获取上级网格名称和ID
							} else {
								me.$message({message: '重点客户变更失败', type: 'warning'});
							}
						}
					});},
				changeType:function (data,index){
					var me =this;
					me.getRemindDetail(data[index].remindId,data[index].remindFlg)
					me.updateType(data[index].remindId,data[index].readFlg,data[index].remindFlg)
					data[index].readFlg = 1
				},
				//更新已读标志
				updateType:function (remindId,readFlg,remindFlg){
					var me= this;
					yufp.service.request({
						url: '/api/dashBoard/updateReadFlg',
						method: 'POST',
						data: JSON.stringify({
							remindId:remindId,
							userNo:yufp.session.userId,
							readFlg:readFlg,
							remindFlg:remindFlg
						}),
						callback: function(code, message, response) {
							let integralCode = null;
							if (response.data === 1) {
								me.getTaskOverview()
								if (remindFlg === '01' || remindFlg === '02' || remindFlg === '03') {
									integralCode = '01'
									yufp.util.addIntegral(integralCode)
									me.getProductExpiration()
								}
								else if (remindFlg === '04') {
									integralCode = '02'
									yufp.util.addIntegral(integralCode)
									me.getRepaymentReminder()
								}
								else if (remindFlg === '05') {
									integralCode = '03'
									yufp.util.addIntegral(integralCode)
									me.getOverdueReminder()
								}
								else if (remindFlg === '06') {
									integralCode = '04'
									yufp.util.addIntegral(integralCode)
									me.getCustomerBirthday()
								}
								else if (remindFlg === '07') {
									integralCode = '05'
									yufp.util.addIntegral(integralCode)
									me.getLargeMovingAccount()
								}
								else if (remindFlg === '10') {
									integralCode = '06'
									yufp.util.addIntegral(integralCode)
									me.getWithdrawalInAdvance()
								}
								else if (remindFlg === '08'|| remindFlg === '09') {
									integralCode = '07'
									yufp.util.addIntegral(integralCode)
									if (remindFlg === '08'){
										me.getImportantCust()
									}
									if (remindFlg === '09'){
										me.getWealthReminder()
									}
								}
							}
						}
					});
				},
				getTaskOverview:function (){
					var me= this;
					yufp.service.request({
						url: '/api/homePageTask/getTaskOverview',
						method: 'GET',
						data: {
							condition: JSON.stringify({
								userNo: yufp.session.userId,
							})
						},callback: function(code, message, response) {
							me.productExpirationUndo=0;
							me.repaymentReminderUndo=0;
							me.customerBirthdayUndo=0;
							me.overdueReminderUndo=0;
							me.largeMovingAccountUndo=0;
							me.importantCustUndo=0;
							me.wealthReminderUndo=0;
							me.withdrawalInAdvanceUndo=0;
							// me.customerBirthdayData =response.data;
							for (let i=0 ;i<response.data.length;i++){
								if (response.data[i].remindFlg==='01' ||
									response.data[i].remindFlg==='02' ||
									response.data[i].remindFlg==='03'){
									me.productExpirationUndo += parseInt(response.data[i].taskUndoNum)
								}
								else if(response.data[i].remindFlg==='04'){
									me.repaymentReminderUndo = response.data[i].taskUndoNum
								}
								else if(response.data[i].remindFlg === '05'){
									me.overdueReminderUndo = response.data[i].taskUndoNum
								}
								else if(response.data[i].remindFlg === '06'){
									me.customerBirthdayUndo = response.data[i].taskUndoNum
								}
								else if(response.data[i].remindFlg === '07'){
									me.largeMovingAccountUndo = response.data[i].taskUndoNum
								}
								else if(response.data[i].remindFlg === '08'){
									me.importantCustUndo = response.data[i].taskUndoNum
								}
								else if(response.data[i].remindFlg === '09'){
									me.wealthReminderUndo = response.data[i].taskUndoNum
								}
								else if(response.data[i].remindFlg === '10'){
									me.withdrawalInAdvanceUndo = response.data[i].taskUndoNum
								}
							}
						}
					});
				},
				handleClick: function (tab, event) {
					yufp.logger.info(tab, event);
				},
				//消息提醒页面弹窗
				getRemindDetail:function (remindId,remindFlg){
					var me= this;
					yufp.service.request({
						url: '/api/dashBoard/getRemindInfo',
						method: 'GET',
						data: {
							condition: JSON.stringify({
								remindId: remindId,
								remindFlg: remindFlg,
							})
						},callback: function(code, message, response) {
							me.showDialog('remindForm')
							me.remindInfo.custName =response.data.custName;
							me.remindInfo.telNo =response.data.telNo;
							me.remindInfo.custLevel =response.data.custLevel;
							me.isImport =response.data.isImport;
							me.remindInfo.custNo =response.data.custNo;
							me.custNo =response.data.custNo;
							if (response.data.remindFlg==='01' ||
								response.data.remindFlg==='02' ||
								response.data.remindFlg==='03'){
								me.remindInfo.remindDetail = response.data.prodNmFinc+"产品要到期了，请及时处理,到期金额为" + response.data.bal
							}
							else if(response.data.remindFlg==='04'){
								me.remindInfo.remindDetail = response.data.prodNmLoan+"贷款要还款了,其中"+response.data.rpybPpal+"还款应还本金"+
									response.data.rpybInt+"还款应还利息"+response.data.repyPpalDt+"前还款还本"+response.data.repyIntDt+"前还款还息"
							}
							else if(response.data.remindFlg === '05'){
								me.remindInfo.remindDetail = "要逾期了"
							}
							else if(response.data.remindFlg === '06'){
								me.remindInfo.remindDetail = "生日要来了，生日为"+response.data.etlDt
							}
							else if(response.data.remindFlg === '06'){
								me.remindInfo.remindDetail = "注意关注该重点客户"
							}
							else if(response.data.remindFlg === '07'){
								me.remindInfo.remindDetail = "大额动账交易金额为"+response.data.trnsAmt
							}
							else if(response.data.remindFlg === '08'){
								me.remindInfo.remindDetail = "AUM为"+response.data.aum
							}
							else if(response.data.remindFlg === '09'){
								me.remindInfo.remindDetail = "AUM为"+response.data.aum
							}
							else if(response.data.remindFlg === '10'){
								me.remindInfo.remindDetail = response.data.prodNmFinc+"产品"+"提前支取金额为"+response.data.bal
							}
						}
					});
				},
				getCustomerBirthday:function (){
					var me= this;
					yufp.service.request({
						url: '/api/dashBoard/getCustomerBirthday',
						method: 'GET',
						data: {
							condition: JSON.stringify({
								userId: yufp.session.userId,
								orgId: yufp.session.user.org.code,
								roleId:yufp.session.user.roles[0].code,
							})
							// userId: vm.userId
						},callback: function(code, message, response) {
							me.customerBirthdayData =response.data;

						}
					});
				},getProductExpiration:function (){
					var me= this;
					yufp.service.request({
						url: '/api/dashBoard/getProductExpiration',
						method: 'GET',
						data: {
							condition: JSON.stringify({
								userId: yufp.session.userId,
								orgId: yufp.session.user.org.code,
								roleId:yufp.session.user.roles[0].code,
							})
							// userId: vm.userId
						},callback: function(code, message, response) {
							me.productExpirationData =response.data;

						}
					});
				},getOverdueReminder:function (){
					var me= this;
					yufp.service.request({
						url: '/api/dashBoard/getOverdueReminder',
						method: 'GET',
						data: {
							condition: JSON.stringify({
								userId: yufp.session.userId,
								orgId: yufp.session.user.org.code,
								roleId:yufp.session.user.roles[0].code,
							})
							// userId: vm.userId
						},callback: function(code, message, response) {
							me.overdueReminderData =response.data;

						}
					});
				},getLargeMovingAccount:function (){
					var me= this;
					yufp.service.request({
						url: '/api/dashBoard/getLargeMovingAccount',
						method: 'GET',
						data: {
							condition: JSON.stringify({
								userId: yufp.session.userId,
								orgId: yufp.session.user.org.code,
								roleId:yufp.session.user.roles[0].code,
							})
							// userId: vm.userId
						},callback: function(code, message, response) {
							me.largeMovingAccountData =response.data;

						}
					});
				},getImportantCust:function (){
					var me= this;
					yufp.service.request({
						url: '/api/dashBoard/getImportantCust',
						method: 'GET',
						data: {
							condition: JSON.stringify({
								userId: yufp.session.userId,
								orgId: yufp.session.user.org.code,
								roleId:yufp.session.user.roles[0].code,
							})
							// userId: vm.userId
						},callback: function(code, message, response) {
							me.importantCustData =response.data;

						}
					});
				},getWealthReminder:function (){
					var me= this;
					yufp.service.request({
						url: '/api/dashBoard/getWealthReminder',
						method: 'GET',
						data: {
							condition: JSON.stringify({
								userId: yufp.session.userId,
								orgId: yufp.session.user.org.code,
								roleId:yufp.session.user.roles[0].code,
							})
							// userId: vm.userId
						},callback: function(code, message, response) {
							me.wealthReminderData =response.data;

						}
					});
				},getWithdrawalInAdvance:function (){
					var me= this;
					yufp.service.request({
						url: '/api/dashBoard/getWithdrawalInAdvance',
						method: 'GET',
						data: {
							condition: JSON.stringify({
								userId: yufp.session.userId,
								orgId: yufp.session.user.org.code,
								roleId:yufp.session.user.roles[0].code,
							})
							// userId: vm.userId
						},callback: function(code, message, response) {
							me.withdrawalInAdvanceData =response.data;

						}
					});
				},getRepaymentReminder:function (){
					var me= this;
					yufp.service.request({
						url: '/api/dashBoard/getRepaymentReminder',
						method: 'GET',
						data: {
							condition: JSON.stringify({
								userId: yufp.session.userId,
								orgId: yufp.session.user.org.code,
								roleId:yufp.session.user.roles[0].code,
							})
							// userId: vm.userId
						},callback: function(code, message, response) {
							me.repaymentReminderData =response.data;

						}
					});
				},
				getCustAssetDistr:function (){
					var me= this;
					yufp.service.request({
						url: '/api/dashBoard/getCustAssetDistr',
						method: 'GET',
						data: {
							condition: JSON.stringify({
								userId: yufp.session.userId,
								orgId: yufp.session.user.org.code,
								roleId:yufp.session.user.roles[0].code,
							})
						},callback: function(code, message, response) {
							me.echartOptionzc ={
								color: ['#FADE8F', '#57B6EF', '#D66A6F', '#95D15F', '#3AB0EB'],
								tooltip: {
									trigger: 'item',
									formatter: '{a} <br/>{b}: {c} ({d}%)'
								},
								series: [{
									name: '客户资产分布',
									type: 'pie',
									center: ['50%', '50%'],
									radius: '70%',
									avoidLabelOverlap: false,
									label: {
										normal: {
											show: true,
											formatter: "{b}\n{c} ",
										},
									},
									labelLine: {
										normal: {
											show: true,
											lineStyle: {
												color: 'grey',
												type: 'dotted'
											}
										}
									},
									data: [{
										value: response.data[0] ? (response.data[0].depBal/10000).toFixed(2) :null,
										name: '存款'
									},
										{
											value: response.data[0] ? (response.data[0].loanBal/10000).toFixed(2):null,
											name: '贷款'
										},
										{
											value: response.data[0] ? (response.data[0].fincBal/10000).toFixed(2) :null,
											name: '理财'
										},
										{
											value: response.data[0] ? (response.data[0].fundBal/10000).toFixed(2) :null,
											name: '基金'
										}
									]
								}]
							}

						}
					});
				},
				getTransformationNumberList:function (){
					var me= this;
					yufp.service.request({
						url: '/api/dashBoard/getRedBlackList',
						method: 'GET',
						data: {
							condition: JSON.stringify({
								userId: yufp.session.userId,
								orgId: yufp.session.user.org.code,
								roleId:yufp.session.user.roles[0].code,
								listType:'01',
							})
							// userId: vm.userId
						},callback: function(code, message, response) {
							me.transformationNumberData =response.data;

						}
					});
				},getConversionRateList:function (){
					var me= this;
					yufp.service.request({
						url: '/api/dashBoard/getRedBlackList',
						method: 'GET',
						data: {
							condition: JSON.stringify({
								userId: yufp.session.userId,
								orgId: yufp.session.user.org.code,
								roleId:yufp.session.user.roles[0].code,
								listType:'02',
							})
							// userId: vm.userId
						},callback: function(code, message, response) {
							me.conversionRateData =response.data;

						}
					});
				},
				getEachGridData:function (){
					var me= this;
					yufp.service.request({
						url: '/api/dashBoard/getEachGridData',
						method: 'GET',
						data: {
							condition: JSON.stringify({
								limit:5,
								userId: yufp.session.userId,
								orgId: yufp.session.user.org.code,
								roleId:yufp.session.user.roles[0].code,
							})
						},callback: function(code, message, response) {
							let gridNameList =[];
							let custNumAddList =[];
							let custNumSumList =[];
							for (let i=0;i<response.data.length;i++){
								gridNameList.push(response.data[i].secondGridName)
								custNumAddList.push(response.data[i].custNumAdd)
								custNumSumList.push(response.data[i].custNumSum)
							}
							me.echartOptiongl ={
								color: ['#FADE8F', '#57B6EF'],
								tooltip: {
									trigger: 'axis',
									axisPointer: {            // 坐标轴指示器，坐标轴触发有效
										type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
									}
								},
								legend: {
									data: ['网格客户数', '增加我行客户数']
								},
								grid: {
									top: 28,
									left: 0,
									right: 0,
									bottom: 0,
									containLabel: true
								},
								xAxis: {
									type: 'category',
									// data: gridName,
									data: gridNameList,
									axisTick: {
										show: false
									},
									axisLine: {
										lineStyle: {
											color: '#E0E0E0'
										}
									}
								},
								yAxis: {
									type: 'value',
									axisLine: {
										lineStyle: {
											color: '#E0E0E0'
										}
									},
									axisTick: {
										show: false
									},
									splitLine: {
										lineStyle: {
											color: '#EDEDED'
										}
									}
								},
								textStyle: {
									color: '#949494'
								},
								series: [{
									name: '网格客户数',
									type: 'bar',
									stack: '网格客户',
									barWidth: '50%',
									emphasis: {
										focus: 'series'
									},
									data: custNumSumList
								},
									{
										name: '增加我行客户数',
										type: 'bar',
										stack: '网格客户',
										barWidth: '50%',
										emphasis: {
											focus: 'series'
										},
										data: custNumAddList
									},
								]
							}

						}
					});
				},
				getGridMainData:function (){
					var me= this;
					yufp.service.request({
						url: '/api/dashBoard/getGridMainData',
						method: 'GET',
						data: {
							condition: JSON.stringify({
								userId: yufp.session.userId,
								orgId: yufp.session.user.org.code,
								roleId:yufp.session.user.roles[0].code,
							})
						},callback: function(code, message, response) {
							if (response.data[0]) {
								me.mainData = response.data[0]
							}
						}
					})},
				getPublishedBoard:function (){
					var me= this;
					yufp.service.request({
						url: '/api/dashBoard/getPublishedBoard',
						method: 'GET',
						async: false,
						data: {
							condition: JSON.stringify({
								userId: yufp.session.userId,
								orgId: yufp.session.user.org.code,
								roleId:yufp.session.user.roles[0].code,
							})
							// userId: vm.userId
						},callback: function(code, message, response) {
							me.noticeData =response.data;

						}
					});
				},
			},}
		);
	}; exports.onmessage = function(type, message, cite, vm) {
		// type 01
		if (type == 'themes') {
			vm.themeColor = message.color;
		}
	};
});
